package models;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;

import enums.RecipientType;

@Table(name = "recipient")
@javax.persistence.Entity
public class Recipient extends Entity<Long> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_mensaje")
	@JsonIgnore
	private Mensaje mensaje;
	@Column(name = "tipo")
	@Enumerated(EnumType.STRING)
	private RecipientType tipo;
	@Column(name = "id_recipient")
	private Long idRecipient;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getIdRecipient() {
		return idRecipient;
	}

	public void setIdRecipient(Long idRecipient) {
		this.idRecipient = idRecipient;
	}

	public services.NotificationsSrv.Channel toChannel() {
		switch (getTipo()) {
		case ESTUDIANTE:
			return new services.NotificationsSrv.EstudianteR(idRecipient);
		case GRADO:
			return new services.NotificationsSrv.GradoR(idRecipient);
		case CURSO:
			return new services.NotificationsSrv.CursoR(idRecipient);
		case COLEGIO:
			return new services.NotificationsSrv.ColegioR(idRecipient);
		}
		return null;
	}

	public RecipientType getTipo() {
		return tipo;
	}

	public void setTipo(RecipientType tipo) {
		this.tipo = tipo;
	}

	public Mensaje getMensaje() {
		return mensaje;
	}

	public void setMensaje(Mensaje mensaje) {
		this.mensaje = mensaje;
	}

}
